﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace UDS.Components
{
    /// <summary>
    /// Desktop 的摘要说明。
    /// </summary>
    /// 
    public class Desktop
    {
        /// <summary>
        /// 得到我的最新文档
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <param name="RightCode">查看文档的权限代号</param>
        /// <returns>返回dataReader</returns>
        public SqlDataReader GetMyDocument(string UserName, int RightCode)
        {
            var data = new Database();
            // 执行存储过程，并返回SqlDataReader对象
            var parameters = new[]
            {
                Database.MakeInParam("@UserName", SqlDbType.NVarChar, 300, UserName),
                Database.MakeInParam("@RightCode", SqlDbType.Int, 4, RightCode)
            };

            try
            {
                return data.RunDataReader("dbo.sproc_GetMyNewDoc", parameters);
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
                throw new Exception("读取我的文档出错!", ex);
            }
        }

        /// <summary>
        /// 得到我的最新收件
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <param name="MailFolderType">收件夹代号</param>
        /// <returns>返回dataReader</returns>
        public SqlDataReader GetMyMail(string UserName, int MailFolderType)
        {
            var data = new Database();

            // 执行存储过程，并返回SqlDataReader对象
            var parameters = new[]
            {
                Database.MakeInParam("@UserName", SqlDbType.NVarChar, 20, UserName),
                Database.MakeInParam("@MailFolderType", SqlDbType.Int, 4, MailFolderType)
            };

            try
            {
                return data.RunDataReader("dbo.sproc_MailGetBriefInfo", parameters);
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
                throw new Exception("读取我的邮件出错!", ex);
            }
        }

        /// <summary>
        /// 得到我的最新审批
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <param name="RightCode">审批权限代号</param>
        /// <returns>返回dataReader</returns>
        public SqlDataReader GetMyApprove(string UserName, int RightCode)
        {
            var data = new Database();

            // 执行存储过程，并返回SqlDataReader对象
            var parameters = new[]
            {
                Database.MakeInParam("@UserName", SqlDbType.NVarChar, 300, UserName),
                Database.MakeInParam("@RightCode", SqlDbType.Int, 4, RightCode)
            };

            try
            {
                return data.RunDataReader("dbo.sproc_GetMyApproved", parameters);
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
                throw new Exception("读取我的审批出错!", ex);
            }
        }
    }
}